import { ActionType } from "./actionTypes";

interface UserInfo{
    name:string
}
export interface IState{
    token:string,
    userInfo:UserInfo,
    list:string[]
}

export interface IAction{
    type:string,
    data:UserInfo | string | string[]
}

const defaultState:IState={
    token:"abc",
    userInfo:{name:"张三"},
    list:["a","b"]
}
export default (state=defaultState,action:IAction)=>{

    console.log("action",action);
      const {type,data}=action;

    if(type==ActionType.修改token){
        return {...state,token:data};
    }
    
    if(type==ActionType.修改用户){
        return {...state,userInfo:data};
    }
    if(type==ActionType.添加){
        return {...state,list:[...state.list,data]};
    }
    
    return state;

}